<!--
 * Copyright (c) 2013-Now http://jeesite.com All rights reserved.
 * No deletion without permission, or be held responsible to law.
 * @author FIRE
-->
<template>
  <BasicDrawer
    v-bind="$attrs"
    :showFooter="false"
    :okAuth="'shop:order:cusFpApply:edit'"
    @register="registerDrawer"
    width="90%"
  >
    <template #title>
      <Icon :icon="getTitle.icon" class="pr-1 m-1" />
      <span> {{ getTitle.value }} </span>
    </template>

    <BasicTable @register="registerTable">
      <template #tableTitle>
        <Icon :icon="getTitle.icon" class="m-1 pr-1" />
        <span> {{ getTitle.value }} </span>
      </template>
    </BasicTable>
  </BasicDrawer>
</template>
<script lang="ts">
  export default defineComponent({
    name: 'ViewsShopOrderCusFpApplyForm',
  });
</script>
<script lang="ts" setup>
  import { defineComponent, ref, computed } from 'vue';
  import { useI18n } from '/@/hooks/web/useI18n';
  import { useMessage } from '/@/hooks/web/useMessage';
  import { router } from '/@/router';
  import { Icon } from '/@/components/Icon';
  import { BasicForm, FormSchema, useForm, FormProps } from '/@/components/Form';
  import { BasicTable, BasicColumn, useTable } from '/@/components/Table';
  import { BasicDrawer, useDrawerInner, useDrawer } from '/@/components/Drawer';
  import { kpRdsListData } from '/@/api/shop/order/cusFpApply';

  const { t } = useI18n('shop.order.cusFpApply');
  const getTitle = computed(() => ({
    icon: router.currentRoute.value.meta.icon || 'ant-design:book-outlined',
    value: t('查看开票订单情'),
  }));

  const searchForm: FormProps = {
    baseColProps: { lg: 6, md: 8 },
    labelWidth: 90,
    schemas: [
      {
        label: t('存货编码'),
        field: 'basInv.cinvcode',
        component: 'Input',
      },
      {
        label: t('存货名称'),
        field: 'basInv.cinvname',
        component: 'Input',
      },
      {
        label: t('是否赠品'),
        field: 'bgift',
        component: 'Select',
        componentProps: {
          dictType: 'sys_yes_no',
          allowClear: true,
        },
      },
    ],
  };

  const tableColumns: BasicColumn[] = [
    {
      title: t('存货编码'),
      dataIndex: 'basInv.cinvcode',
      key: 'a.cinvcode',
      sorter: true,
      width: 120,
      align: 'left',
      slot: 'firstColumn',
    },
    {
      title: t('存货名称'),
      dataIndex: 'basInv.cinvname',
      key: 'a.cinvname',
      sorter: true,
      width: 150,
      align: 'left',
    },
    {
      title: t('单位'),
      dataIndex: 'basInv.unitName',
      key: 'a.unitName',
      sorter: true,
      width: 200,
      align: 'left',
    },
    {
      title: t('数量'),
      dataIndex: 'iquantity',
      key: 'a.iquantity',
      sorter: true,
      width: 100,
      align: 'right',
    },
    {
      title: t('价税合计'),
      dataIndex: 'itaxunitprice',
      key: 'a.isum',
      sorter: true,
      width: 80,
      align: 'right',
    },
    {
      title: t('价税合计'),
      dataIndex: 'isum',
      key: 'a.isum',
      sorter: true,
      width: 120,
      align: 'right',
    },
    {
      title: t('使用返利'),
      dataIndex: 'cbdefine5',
      key: 'a.cbdefine5',
      sorter: true,
      width: 120,
      align: 'right',
    },

    {
      title: t('使用促销'),
      dataIndex: 'cbdefine1',
      key: 'a.cbdefine1',
      sorter: true,
      width: 120,
      align: 'right',
    },
    {
      title: t('是否赠品'),
      dataIndex: 'bgift',
      key: 'a.bgift',
      sorter: true,
      width: 90,
      align: 'center',
      dictType: 'sys_yes_no',
    },
  ];

  let id = ref<any>('');
  const [registerDrawer, { setDrawerProps }] = useDrawerInner(async (data) => {
    setDrawerProps({ loading: true });
    console.log(data);
    id.value = data.id;
    setDrawerProps({ loading: false });
  });

  const [registerTable, { reload, getForm, getSelectRowKeys }] = useTable({
    api: kpRdsListData,
    beforeFetch: (params) => {
      console.log(params);
      params['applyId.id'] = id.value;
      return params;
    },
    columns: tableColumns,
    // actionColumn: actionColumn,
    formConfig: searchForm,
    showTableSetting: true,
    useSearchForm: true,
    canResize: true,
    rowSelection: {
      type: 'checkbox',
    },
  });
  function handleSuccess() {
    reload();
  }
</script>
